/**
 * 
 */
package com.google.code.cisx.gwt.client.session;

/**
 * Utility class to keep track of a user session.
 * 
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @since 1.0
 * @version $Id: SessionTracker.java 266 2009-01-21 06:38:36Z rahul.thakur.xdev $
 */
public final class SessionTracker {

  /**
   * Singleton {@link SessionTracker} instance.
   */
  private static final SessionTracker instance = new SessionTracker();

  /**
   * Only one user session on the client to keep track of.
   */
  private Session session;

  /**
   * Private!
   */
  private SessionTracker() {
    // no touchy!
  }

  /**
   * Returns a singleton instance of {@link SessionTracker}.
   * 
   * @return
   */
  public static SessionTracker getInstance() {
    return instance;
  }

  /**
   * Bind a session to the Tracker.
   * 
   * @param newSession
   */
  public void bindSession(Session newSession) {
    unbindSession(); // unbind any existing sessions.
    session = newSession;
  }

  /**
   * Unbind a session from the tracker.
   */
  public void unbindSession() {
    session = null;
  }

  /**
   * @return the session
   */
  public Session getSession() {
    return session;
  }

}
